package com.example.interfacecall.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.interfacecall.domain.Book;
import com.example.interfacecall.domain.Result;
import com.example.interfacecall.util.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class HtmlController {
    private static final Logger LOGGER = LoggerFactory.getLogger(HtmlController.class);

    @Value("${interface.url}")
    private String interfaceurl;


    //所调用的接口
    @RequestMapping(value = "/test", method = { RequestMethod.GET,RequestMethod.POST })
    @ResponseBody
    public Result test(HttpServletRequest request)throws Exception {
       String interfaceName = "baohanapply";
       String url = interfaceurl +"/"+ interfaceName;
       String s= HttpUtils.sendGet(url, "");
        Result result = JSONObject.parseObject(s,Result.class);
        return result;
    }

    @RequestMapping(value = "/mynearby")
    public ModelAndView myNearby(Model model)
    {
        List<Book> books = new ArrayList<>();
        Book b1 = new Book();
        b1.setId(1);
        b1.setAuthor("罗贯中");
        b1.setName("三国演义");
        Book b2 = new Book();
        b2.setId(2);
        b2.setAuthor("曹雪芹");
        b2.setName("红楼梦");
        books.add(b1);
        books.add(b2);
        ModelAndView mv = new ModelAndView();
        mv.addObject("books", books);
        mv.setViewName("baohannotice");
        return mv;
    }



}
